module CnSms
  class SMS
    @@sms_sender = nil

    def self.send(phone,msg)
      initialize_sms_sender
      @@sms_sender.send(phone,msg)
    end

    protected
    def self.initialize_sms_sender
      if (@@sms_sender.nil?)
        options = YAML.load_file("config/sms.yml")
        adapter = options[ENV["RACK_ENV"]]["type"].capitalize
        sms_adapter = "CnSms::Adapter::#{adapter}".constantize
        @@sms_sender = sms_adapter.new(options[ENV["RACK_ENV"]])
      end
    end
  end
end